package com.sc.nft.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.entity.EcologyCastExchangeConf;
import com.sc.nft.enums.EcologyExpendType;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyCastExpendConf;
import com.sc.nft.mapper.EcologyCastExpendConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 生态-铸造-消耗-配置(sc_ecology_cast_expend_conf)数据DAO
 *
 * @author Sun
 * @since 2023-10-13 17:22:11
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class EcologyCastExpendConfDao extends ServiceImpl<EcologyCastExpendConfMapper, EcologyCastExpendConf> {

    public EcologyCastExpendConf getOneByIdAndEcologyCastConfId(Long id, Long ecologyCastConfId) {
        return this.lambdaQuery()
                .eq(EcologyCastExpendConf::getId, id)
                .eq(EcologyCastExpendConf::getEcologyCastConfId, ecologyCastConfId)
                .one();
    }

    public List<EcologyCastExpendConf> getListByEcologyCastConfId(Long ecologyCastConfId) {
        LambdaQueryWrapper<EcologyCastExpendConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastExpendConf::getEcologyCastConfId, ecologyCastConfId);
        return list(wrapper);
    }

    /**
     * 根据方式id获取消耗配置
     * @param ecologyCastWayConfId
     * @return
     */
    public List<EcologyCastExpendConf> getListByEcologyCastWayConfId(Long ecologyCastWayConfId) {
        LambdaQueryWrapper<EcologyCastExpendConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastExpendConf::getEcologyCastWayConfId, ecologyCastWayConfId);
        return list(wrapper);
    }
    /**
     * 根据方式idList获取消耗配置
     * @param ecologyCastWayConfIdList
     * @return
     */
    public List<EcologyCastExpendConf> getListByEcologyCastWayConfIdList(List<Long> ecologyCastWayConfIdList) {
        LambdaQueryWrapper<EcologyCastExpendConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(EcologyCastExpendConf::getEcologyCastWayConfId, ecologyCastWayConfIdList);
        return list(wrapper);
    }

    public boolean delExpendById(Long id) {
        return this.lambdaUpdate()
                .eq(EcologyCastExpendConf::getId, id)
                .remove();
    }

    public boolean delByEcologyCastConfId(Long ecologyCastConfId) {
        return this.lambdaUpdate()
                .eq(EcologyCastExpendConf::getEcologyCastConfId, ecologyCastConfId)
                .remove();
    }

    /**
     * 获取生态铸造消耗的道具卡
     * @param ecologyCastIds
     * @return
     */
    public List<EcologyCastExpendConf> getListByCastIds(List<Long> ecologyCastIds) {
        LambdaQueryWrapper<EcologyCastExpendConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(EcologyCastExpendConf::getEcologyCastConfId, ecologyCastIds);
        wrapper.eq(EcologyCastExpendConf::getExpendType, EcologyExpendType.EQUITY_PROPS);
        return list(wrapper);
    }

    /**
     * 获取生态铸造消耗的道具卡
     * @param ecologyCastId
     * @return
     */
    public EcologyCastExpendConf getListByCastId(Long ecologyCastId) {
        LambdaQueryWrapper<EcologyCastExpendConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCastExpendConf::getEcologyCastConfId, ecologyCastId);
        wrapper.eq(EcologyCastExpendConf::getExpendType, EcologyExpendType.EQUITY_PROPS);
        wrapper.last("ORDER BY ID DESC LIMIT 1");
        return getOne(wrapper);
    }

    public boolean updateWayConfIdByEcologyCastConfId(Long confId, Long wayConfId) {
        LambdaUpdateWrapper<EcologyCastExpendConf> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(EcologyCastExpendConf::getEcologyCastConfId, confId);
        wrapper.set(EcologyCastExpendConf::getEcologyCastWayConfId,wayConfId);
        return update(wrapper);
    }
}